package se.teamscape.client.place;

import net.customware.gwt.presenter.client.gin.ProvidedPresenterPlace;
import net.customware.gwt.presenter.client.place.PlaceRequest;
import se.teamscape.client.presenter.ShowPersonPresenter;

import com.google.inject.Inject;
import com.google.inject.Provider;

/**
 * Place implementation linked to a presenter.
 * 
 * @author Andreas Borglin
 * 
 */
public class ShowPersonPlace extends ProvidedPresenterPlace<ShowPersonPresenter> {

    public static final String NAME = "ShowPerson";
    public static final String PARAM_ID = "id";

    @Inject
    public ShowPersonPlace(Provider<ShowPersonPresenter> presenter) {
        super(presenter);
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    protected void preparePresenter(PlaceRequest request, ShowPersonPresenter presenter) {

        String id = request.getParameter(PARAM_ID, null);
        presenter.setId(id);
    }

    @Override
    protected PlaceRequest prepareRequest(PlaceRequest request, ShowPersonPresenter presenter) {

        if (presenter.getId() != null) {
            request = request.with(PARAM_ID, presenter.getId());
        }

        return request;
    }

}
